package no.group.gowther.rest;

import com.fasterxml.jackson.databind.JsonNode;
import no.group.gowther.util.JsonUtils;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

public class RestTestUtils {
    public static JsonNode afterPerform(ResultActions resultActions) throws Exception {
        resultActions.andReturn().getResponse().setContentType("application/json;charset=UTF-8");
        resultActions.andDo(MockMvcResultHandlers.print());
        resultActions.andExpect(MockMvcResultMatchers.status().isOk());
        return JsonUtils.toJsonNode(resultActions.andReturn().getResponse().getContentAsString());
    }
}
